﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using thinger.MTHDAL;
using thinger.MTHModels;
using System.Data;

namespace thinger.MTHDLL
{
    /// <summary>
    /// 用户的管理
    /// </summary>
    public class SysAdminManage
    {
        private SysAdminServer sysAdminServer = new SysAdminServer();
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sysAdmin"></param>
        /// <returns></returns>
        public SysAdmin AdminLog(SysAdmin sysAdmin)
        {
            return sysAdminServer.AdminLogin(sysAdmin);
        }

       

        public List<SysAdmin> AdminLogAll()
        {
            try
            {
                List<SysAdmin> sysAdmins = new List<SysAdmin>();
                DataTable dataTable = sysAdminServer.AdminLoginAll();
                for (int i = 0; i < dataTable.Rows.Count; i++)
                {
                    SysAdmin sysAdmin = new SysAdmin()
                    {
                        LoginId = (int)dataTable.Rows[i]["LoginId"],
                        LoginName = dataTable.Rows[i]["LoginName"].ToString(),
                        LoginPwd = dataTable.Rows[i]["LoginPwd"].ToString(),
                        ParamSet = dataTable.Rows[i]["ParamSet"].ToString().Trim() == "1" ? true : false,
                        Recipe = dataTable.Rows[i]["Recipe"].ToString().Trim() == "1" ? true : false,
                        HistoryLog = dataTable.Rows[i]["HistoryLog"].ToString().Trim() == "1" ? true : false,
                        HistoryTrend = dataTable.Rows[i]["HistoryTrend"].ToString().Trim() == "1" ? true : false,
                        UserManage = dataTable.Rows[i]["UserManage"].ToString().Trim() == "1" ? true : false,
                    };
                    sysAdmins.Add(sysAdmin);

                }
                return sysAdmins;
            }
            catch (Exception)
            {

                return null;
            }
            
        }

        public int AddLogin(SysAdmin sysAdmin)
        {
            try
            {
                return sysAdminServer.AddLogin(sysAdmin);
            }
            catch (Exception)
            {

                return -1;
            }
            

        }

        public int UpdateLogin(SysAdmin sysAdmin)
        {
            try
            {
                return sysAdminServer.UpdateLogin(sysAdmin);
            }
            catch (Exception)
            {

                return -1;
            }
            
        }

        public int DeleteLogin(SysAdmin sysAdmin)
        {
            try
            {
                return sysAdminServer.DeleteAdmin(sysAdmin);
            }
            catch (Exception)
            {

                return -1;
            }
            
        }


    }
}
